package com.rightsidetech.http.controller.storeApp.coupon;

import cn.hutool.core.util.ObjectUtil;
import com.rightsidetech.activity.dto.response.ActStoreCouponResp;
import com.rightsidetech.activity.service.ActAgentAppCouponService;
import com.rightsidetech.commom.base.ResponseData;
import com.rightsidetech.commom.enums.CodeIdEnum;
import com.rightsidetech.http.aspect.Token;
import com.rightsidetech.http.base.BaseController;
import com.rightsidetech.system.entity.store.SysStoreInfo;
import com.rightsidetech.system.service.SysStoreInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shenyu.client.springmvc.annotation.ShenyuSpringMvcClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: yhr
 * @Date: 2022-01-11 11:03
 */
@RequestMapping("/storeApp/coupon")
@Api(tags = "优惠券门店优惠券相关")
@RestController
@ShenyuSpringMvcClient(path = "/storeApp/coupon/**")
public class AgentAppCouponController extends BaseController {
    @Resource
    private ActAgentAppCouponService actAgentAppCouponService;
    @Resource
    private SysStoreInfoService sysStoreInfoService;

/*    @Token
    @GetMapping("/storeCoupon")
    @ApiOperation("查看优惠券")
    public ResponseData<List<ActAgentAppCouponResp>> storeCoupon(){
        Long storeId = Long.parseLong(getAttribute());
        return actAgentAppCouponService.selectStoreCoupon(storeId);
    }*/

    @Token
    @GetMapping("/storeCoupon")
    @ApiOperation("查看优惠券")
    public ResponseData<List<ActStoreCouponResp>> storeCoupon(){
        SysStoreInfo storeInfo = sysStoreInfoService.selectByPrimaryKey(Long.parseLong(getAttribute()));
        if (ObjectUtil.isEmpty(storeInfo)) {
            return ResponseData.fail(CodeIdEnum.ParameterMalformed.getValue(), "未找到登录的门店");
        }
        return actAgentAppCouponService.findByStoreId(storeInfo.getId(),storeInfo.getSysAgentInfoId());
    }

}
